package com.zzt.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description
 * User: panda
 * Date: 2025-03-30
 * Time: 14:16
 */
@Aspect
//@Component
@Slf4j
public class AspectDemo1 {

    @Pointcut("execution(* com.zzt.aop.controller.*.*(..))")
    public void pt(){}

    @Around("pt()")
    public Object doAround(ProceedingJoinPoint pjp) {
        log.info("目标方法执行前...");
        //执行目标方法
        Object result = null;
        try {
            result = pjp.proceed();
        } catch (Throwable e) {
            log.error("do Around throwing...");
        }
        log.info("目标方法执行后...");
        return result;
    }

    @Before("pt()")
    public void doBefore(){
        log.info("doBefore...");
    }

    @After("pt()")
    public void doAfter(){
        log.info("doAfter...");
    }
    @AfterReturning("pt()")
    public void doAfterReturning(){
        log.info("doAfterReturning...");
    }
    @AfterThrowing("pt()")
    public void doAfterThrowing(){
        log.info("doAfterThrowing...");
    }
}
